home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kopete / kopetetransfermanager.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  6.1 KB  |  213 lines

  1. /*
  2.     kopetetransfermanager.h
  3.  
  4.     Copyright (c) 2002-2003 by Nick Betcher <nbetcher@kde.org>
  5.     Copyright (c) 2002-2003 by Richard Smith <kopete@metafoo.co.uk>
  6.  
  7.     Kopete    (c) 2002-2004 by the Kopete developers  <kopete-devel@kde.org>
  8.  
  9.     *************************************************************************
  10.     *                                                                       *
  11.     * This library is free software; you can redistribute it and/or         *
  12.     * modify it under the terms of the GNU Lesser General Public            *
  13.     * License as published by the Free Software Foundation; either          *
  14.     * version 2 of the License, or (at your option) any later version.      *
  15.     *                                                                       *
  16.     *************************************************************************
  17. */
  18.  
  19. #ifndef KOPETEFILETRANSFER_H
  20. #define KOPETEFILETRANSFER_H
  21.  
  22. #include <qobject.h>
  23. #include <qstring.h>
  24. #include <qmap.h>
  25. #include "kopete_export.h"
  26.  
  27. #include <kio/job.h>
  28.  
  29. namespace Kopete
  30. {
  31.  
  32. class Transfer;
  33. class Contact;
  34.  
  35. /**
  36.  * @author Nick Betcher. <nbetcher@kde.org>
  37.  */
  38. class KOPETE_EXPORT FileTransferInfo
  39. {
  40. public:
  41.     enum KopeteTransferDirection { Incoming, Outgoing };
  42.  
  43.     FileTransferInfo( Contact *, const QString&, const unsigned long size, const QString &, KopeteTransferDirection di, const unsigned int id, QString internalId=QString::null);
  44.     ~FileTransferInfo() {}
  45.     unsigned int transferId() const { return mId; }
  46.     const Contact* contact() const { return mContact; }
  47.     QString file() const { return mFile; }
  48.     QString recipient() const { return mRecipient; }
  49.     unsigned long size() const { return mSize; }
  50.     QString internalId() const { return m_intId; }
  51.     KopeteTransferDirection direction() const { return mDirection; }
  52.  
  53. private:
  54.     unsigned long mSize;
  55.     QString mRecipient;
  56.     unsigned int mId;
  57.     Contact *mContact;
  58.     QString mFile;
  59.     QString m_intId;
  60.     KopeteTransferDirection mDirection;
  61. };
  62.  
  63. /**
  64.  * Creates and manages kopete file transfers
  65.  */
  66. class KOPETE_EXPORT TransferManager : public QObject
  67. {
  68.     Q_OBJECT
  69.  
  70. public:
  71.     /**
  72.      * Retrieve the transfer manager instance
  73.      */
  74.     static TransferManager* transferManager();
  75.     virtual ~TransferManager() {};
  76.  
  77.     /**
  78.      * @brief Adds a file transfer to the Kopete::TransferManager
  79.      */
  80.     Transfer *addTransfer( Contact *contact, const QString& file, const unsigned long size, const QString &recipient , FileTransferInfo::KopeteTransferDirection di);
  81.     int askIncomingTransfer( Contact *contact, const QString& file, const unsigned long size, const QString& description=QString::null, QString internalId=QString::null);
  82.     void removeTransfer( unsigned int id );
  83.  
  84.     /**
  85.      * @brief Ask the user which file to send when they click Send File.
  86.      *
  87.      * Possibly ask the user which file to send when they click Send File. Sends a signal indicating KURL to
  88.      * send when the local user accepts the transfer.
  89.      * @param file If valid, the user will not be prompted for a URL, and this one will be used instead.
  90.      *  If it refers to a remote file and mustBeLocal is true, the file will be transferred to the local
  91.      *  filesystem.
  92.      * @param localFile file name to display if file is a valid URL
  93.      * @param fileSize file size to send if file is a valid URL
  94.      * @param mustBeLocal If the protocol can only send files on the local filesystem, this flag
  95.      *  allows you to ensure the filename will be local.
  96.      * @param sendTo The object to send the signal to
  97.      * @param slot The slot to send the signal to. Signature: sendFile(const KURL &file)
  98.      */
  99.     void sendFile( const KURL &file, const QString &localFile, unsigned long fileSize,
  100.         bool mustBeLocal, QObject *sendTo, const char *slot );
  101.  
  102. signals:
  103.     /** @brief Signals the transfer is done. */
  104.     void done( Kopete::Transfer* );
  105.  
  106.     /** @brief Signals the transfer has been canceled. */
  107.     void canceled( Kopete::Transfer* );
  108.  
  109.     /** @brief Signals the transfer has been accepted */
  110.     void accepted(Kopete::Transfer*, const QString &fileName);
  111.  
  112.     /** @brief Signals the transfer has been rejected */
  113.     void refused(const Kopete::FileTransferInfo& );
  114.  
  115.     /** @brief Send a file */
  116.     void sendFile(const KURL &file, const QString &localFile, unsigned int fileSize);
  117.  
  118. private slots:
  119.     void slotAccepted(const Kopete::FileTransferInfo&, const QString&);
  120.     void slotComplete(KIO::Job*);
  121.  
  122. private:
  123.     TransferManager( QObject *parent );
  124.     static TransferManager *s_transferManager;
  125.  
  126.     int nextID;
  127.     QMap<unsigned int, Transfer *> mTransfersMap;
  128. };
  129.  
  130. /**
  131.  * A KIO job for a kopete file transfer.
  132.  * @author Richard Smith <kopete@metafoo.co.uk>
  133.  */
  134. class KOPETE_EXPORT Transfer : public KIO::Job
  135. {
  136.     Q_OBJECT
  137.  
  138. public:
  139.     /**
  140.      * Constructor
  141.      */
  142.     Transfer( const FileTransferInfo &, const QString &localFile, bool showProgressInfo = true);
  143.  
  144.     /**
  145.      * Constructor
  146.      */
  147.     Transfer( const FileTransferInfo &, const Contact *toUser, bool showProgressInfo = true);
  148.  
  149.     /**
  150.      * Destructor
  151.      */
  152.     ~Transfer();
  153.  
  154.     /** @brief Get the info for this file transfer */
  155.     const FileTransferInfo &info() const { return mInfo; }
  156.  
  157.     /**
  158.      * Retrieve a URL indicating where the file is being copied from.
  159.      * For display purposes only! There's no guarantee that this URL
  160.      * refers to a real file being transferred.
  161.      */
  162.     KURL sourceURL();
  163.  
  164.     /**
  165.      * Retrieve a URL indicating where the file is being copied to.
  166.      * See @ref sourceURL
  167.      */
  168.     KURL destinationURL();
  169.  
  170. public slots:
  171.  
  172.     /**
  173.      * @brief Set the file size processed so far
  174.      */
  175.     void slotProcessed(unsigned int);
  176.  
  177.     /**
  178.      * @brief Indicate that the transfer is complete
  179.      */
  180.     void slotComplete();
  181.  
  182.     /**
  183.      * @brief Inform the job that an error has occurred while transferring the file.
  184.      *
  185.      * @param error A member of the KIO::Error enumeration indicating what error occurred.
  186.      * @param errorText A string to aid understanding of the error, often the offending URL.
  187.      */
  188.     void slotError( int error, const QString &errorText );
  189.  
  190. signals:
  191.     /**
  192.      * @deprecated Use result() and check error() for ERR_USER_CANCELED
  193.      */
  194.     void transferCanceled();
  195.  
  196. private:
  197.     void init( const KURL &, bool );
  198.  
  199.     static KURL displayURL( const Contact *contact, const QString &file );
  200.  
  201.     FileTransferInfo mInfo;
  202.     KURL mTarget;
  203.     int mPercent;
  204.  
  205. private slots:
  206.     void slotResultEmitted();
  207. };
  208.  
  209. }
  210.  
  211. #endif
  212. // vim: set noet ts=4 sts=4 sw=4:
  213.